// packageC/pages/takeoutOrder/takeoutOrder.js
const common = require('../../../public.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        height:'',
        top:'',
        num:2,
        orderList:[],
        showOrder:false,
        showCancel:false,
        cansselList:[
            ' 取消订单',
            ' 修改订单信息',
            '狠心取消'
        ]
    },  
      goBack() {
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
    // 订单取消
    click_order(e){
        // console.log(e,"jdjjdjdjjdj")
        let index = e.currentTarget.dataset.item
        if(index==0){
           wx.redirectTo({
             url: '/packageC/pages/takeoutCansel/takeoutCansel',
           })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        //获取胶囊位置
        const that = this
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,
        })
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that.setData({
                    userInfo: data.user,
                    token: data.token,
                    openid: data.openid,
                    orderId: options.orderId ? options.orderId : '176738'
                }, function () {
                    that.getOrderDes()
                })
            }
        }, true)
    },

    getOrderDes: function () {
        var that = this;
        this.setData({
            isLoading: true
        })
        common.post('/order/getOrderDetail', {
            userId: that.data.userInfo.id,
            orderId: that.data.orderId,
            token: that.data.token
        }, function (responseData) {
            if (responseData && responseData.status === 200) {
                console.log(responseData.data, "445566625555566s")
      
                responseData.data[0].postFee = parseFloat(responseData.data[0].postFee)
                responseData.data[0].totalFee = parseFloat(responseData.data[0].totalFee)
                responseData.data[0].payment = parseFloat(responseData.data[0].payment)
                that.setData({
                    finalPayMent:responseData.data[0].payment + responseData.data[0].postFee,
                    orderList: responseData.data,
                    orderDes: responseData.data[0], //订单信息
                    moreGood: responseData.data.length > 2 ? true : false,
                    receiverAddress: responseData.data[0].receiverAddress,
                    receiverMobile: responseData.data[0].receiverMobile
                })
                that.getStoreInfo(responseData.data[0].storeId)
            } else {
                common.showRequestErrMsg(responseData)
            }
        },
            function () {
                that.setData({
                    isLoading: false
                })
            }
        )
    },
    getStoreInfo(storeId) {
        common.post('/store/info', {
                storeId
            },
            (res) => {
                this.setData({
                    storeInfo: res.data
                })
            })
    },
    again_order(){
       wx.navigateTo({
         url: `/packageC/pages/activeBei/activeBei?id=${this.data.orderList[0].storeId}`,
       })
    },
    contact() {
        const mobile = this.data.storeInfo.mobile
        wx.makePhoneCall({
            phoneNumber: mobile
        })
    },
    xiugai_order(){
        this.setData({  showOrder: true });
    },
    onClose() {
        this.setData({  showOrder: false });
      },
    // 查看更多
    click_lenght(){
       this.setData({
          num:6,
          moreGood: false
       })
    },
    // 修改订单信息
    revise_order(){
        this.setData({
            showOrder:true
         })
    },
 
})